package com.test.profile.service;

import com.test.profile.dao.UserDao;
import com.test.profile.dao.UserDaoImpl;
import com.test.profile.pojo.User;

import com.test.profile.util.MD5Utils;

public class UserServiceImpl implements UserService{

    @Override
    public User login(String username, String password) {
        UserDao userDao = new UserDaoImpl();
        User user =userDao.findByusername(username);
        if(user == null){
            return null;
        }
        if("0".equals(user.getStatus())){
            return null;
        }

        String md5Pwd = MD5Utils.md5(password);
        if(md5Pwd.equals(user.getPassword())){
            return user;
        }
        return null;
    }
    @Override
    public int addUser(User user){
        String md5 = MD5Utils.md5(user.getPassword());
        user.setPassword(md5);
        UserDao userDao = new UserDaoImpl();
        int count = userDao.addUser(user);
        return count;
    }
}
